<template>
    <div class="softphone">
      <div class="softphone-status">
        <div>
          <i :class="['kfont', iconClasses]" />{{ extensionMessage2 }}
        </div>
      </div>

      <div class="softphone-operator">
        <div class="item" @click="() => changeState('Ready')">
          <i :class="['kfont', 'icon-30offlineoval']" />
          <span>{{ state === 'Ready' ? "就绪" : "未就绪" }}</span>
        </div>

        <div class="item" @click="() => changeState('Ready')">
          <i class="kfont" :class="'icon-zaixianjieda'" />
          <span>接听</span>
        </div>
        <div class="item" @click="() => changeState('Ready')">
          <i class="kfont" :class="'icon-end-copy'" />
          <span>挂断</span>
        </div>
        <div class="item" @click="() => changeState('Ready')">
          <!--  icon-time-->
          <i class="kfont" :class="'icon-30offlineoval'" />
          <span>空闲</span>
        </div>
        <div class="item" @click="() => changeState('Ready')">
          <i class="kfont icon-Call" />
          <span>拨打</span>
        </div>
<!--        <div class="item" @click="() => changeState('Ready')">-->
<!--          <i :class="['kfont', 'icon-phone4']" />-->
<!--          <span>保持</span>-->
<!--        </div>-->
<!--        <div class="item" @click="() => changeState('Ready')">-->
<!--          <i class='kfont' :class="'icon-call_transfer'" />-->
<!--          <span>转接</span>-->
<!--        </div>-->
        <div class="item" @click="() => changeState('Ready')">
          <i class="kfont icon-phone" />
          <span>外呼</span>
        </div>
      </div>
    </div>
</template>

<script>
import JdWebCall from 'jdcall'
export default {
  name: "ExampleView",
  data() {
    return {
      isLogin: false,
      loginData: {},
      isReady: false,
      jdCall: null,

      state: ''
    }
  },
  computed: {
    extensionMessage2() {
      if (this.isLogin) {
        return `分机${this.loginData.user} 登入成功`
      }
      return '分机未登录，连接失败'
    },
    iconClasses() {
      if (this.isLogin) return 'icon-xuanzhong'
      return 'icon-circle'
    }
  },
  methods: {
    getSeatState() {
      // 主动获取坐席状态
      this.jdCall.events.EventGetState =  (data) => {
        if (data.Result) {
          console.log('获取坐席状态', data.ResultMsg)
          this.state = data.ResultMsg.State;
        }
      }
      this.jdCall.actions.getAgentState()
    },
    readyEvent() {
      this.jdCall.actions.selChange('Ready')
    },
    changeState(state) {
      this.jdCall.events.EventState = (data) => {
        console.log('主动获取状态EventState', data)
      }
      this.jdCall.actions.selChange(state);
    }
  },
  created() {
    const jdCall = JdWebCall.CreateCall({
      callserverurl: 'https://demo.zkefu.cn',
      error(msg) {
        console.error(msg)
      }
    })
    this.jdCall = jdCall;

    // 集成登录
    jdCall.actions.loginbytoken('1004', '', '', 'qwe123', 'ukewo')
    jdCall.events.EventLogin =  (data) => {
      if (data.Result) {
        this.isLogin = true;
        this.loginData = data.ResultMsg;
      }
    }
  }
};
</script>

<style lang="scss" socped>
.softphone {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  color: #fff;
  background-color: #001529;
  display: flex;
  justify-content: center;

  .softphone-status {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    margin-right: 30px;
  }

  &-operator {
    display: flex;

    .item {
      margin: 0 15px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      color: rgba(#fff, 0.6);
      text-align: center;
      font-size: 14px;

      &.on {
        color: #fff;
        cursor: pointer;

        &:hover {
          background-color: rgb(175, 174, 174);
        }
      }

      i {
        font-size: 24px;
      }
    }
  }

  .softphone-call {
    width: 200px;
    height: 50px;
    position: absolute;
    bottom: -60px;
    right: -90px;
  }
}
</style>
